<template>
  <div class="current-page" style="width: 100%">
    <FqueryListens ref="queryListens" :tableHeadList="tableHeadList" @searquFormstr="searquFormstr">
    </FqueryListens>
    <el-row>
      <el-col :span="24">
        <div class="rightTableBox">
          <div class="table-bottom">
            <div class="btn-right">
              <el-button type="primary" plain icon="el-icon-plus" @click="opencliks('add', '')">新增</el-button>
            </div>
            <FcomTable ref="comTable" :tableData="tableData" :table-head-list="tableHeadList" :hasData="hasData"
              :total-count="totalCount" :page-num="pageNum" :url="url" :page-size="pagesize" :page-sizes="pageSizes"
              :table-loading="loading" :table-height="tableHeight" :is-show-select="true" :page-show="true"
              handleWidth="240px" :handle-show="isShow" :merge-flag="false" @selectTableData="selectTableData"
              @getTableData="getTableData">
              <template slot="handle" slot-scope="scope">
                <el-button icon="el-icon-edit" type="text" size="small" @click="opencliks('mod', scope.row)">修改
                </el-button>
                <el-button icon="el-icon-delete" type="text" size="small" class="delete-button">删除
                </el-button>
              </template>
            </FcomTable>
          </div>
        </div>
      </el-col>
    </el-row>
    <FdialogsForm ref="formDialog"></FdialogsForm>
    <!-- <dialogCheckCont ref="checkDialogs" :TitlesName="TitlesName" :dialogCheckControl="dialogCheckControl"
          @checkDialogsClosed="checkDialogsClosed">
          <p>ddd</p>
      </dialogCheckCont> -->
  </div>
</template>
<script>
import formatDesc from "../../components/index"

export default {
  name: "list",
  data() {
    return {
      hasData: true,
      loading: false,
      isShow: true,
      pageSizes: [5, 10, 20, 50, 100],
      TitlesName: "查看详情",
      dialogCheckControl: false,
      tableHeadList: [
        { colDisabled: false, colHidden: false, colSearch: true, colSort: false, columnComment: "组织机构名称", columnName: "orgName", type: "input", nvoid: true, size: 20, cloumnType: true, queryShow: true },
        {
          colDisabled: false, colHidden: false, colSearch: true, colSort: false, columnComment: "联系人", columnName: "orgLinkUser", type: "XOPT", nvoid: true, size: 20, cloumnType: true,
          display_enum: [
            {
              show: '测试',
              value: '111'
            },
          ]
        },
        { colDisabled: false, colHidden: false, colSearch: true, colSort: false, columnComment: "时间", columnName: "ces", type: "time", nvoid: true, size: 20, cloumnType: true },
        // type: XSTR 输入框走校验、strType: "ipStr" 输入框ip校验  nvoid：false/true 是否必填
      ],
      url: "",
      tableHeight: null, // 表格高度
      tableData: [],
      totalCount: 0,
      pagesize: 10, //每页的数据条数
      pageNum: 1, //默认开始页面
      dialogSelectTitle: "xx",
      dialogControl: false,
    }
  },
  created() {
    this.setTableHeight()
    // this.getModelList()
  },
  methods: {
    /**
     * 设置表格的高度
     */
    setTableHeight() {
      let clientHeiht = window.innerHeight || document.documentElement.clientHeight;
      this.tableHeight = clientHeiht - 300;
    },
    selectTableData(selection) {
      console.log(selection)
    },
    getTableData(pageNum, pagesize) {
      this.pagesize = pagesize
      this.pageNum = pageNum
      this.getModelList()
    },
    // 新增修改
    opencliks(type, daJson) {
      let formColumns = formatDesc.get(this.tableHeadList);
      console.log(formColumns)
      let formData = {}
      let formTitle = ''
      let dialogwidth = "40%"
      if (type == 'add') {
        formTitle = '新增';
      } else {
        formTitle = '修改';
        formData = daJson
      }
      let args = { formColumns, formData, formTitle, dialogwidth };
      this.$refs.formDialog.showDialog(args,
        (data) => {
          console.log(data) // 表单里输入的数据
          this.$postForJson('organization/saveOrganization', data).then(res => {
            this.loading = false;
            let { data, msg, success, code } = res.data;
            if (success) {
              this.$message.success(msg);
              this.getModelList()
              this.$refs.formDialog.onHide()
            } else {
              this.publicModal.$emit('tips', {
                show: true,
                publicModalMessage: msg,
                fontIcon: 'errorWarning'
              });
              return false
            }
          })
        }
      )
    },
    // 获取表格数据
    getModelList() {
      this.loading = true
      this.$get(
        `application/listAll`,
      ).then(jsonData => {
        this.loading = false
        console.log(jsonData, "接口调用---")
        let datas = jsonData.data;
        if (!datas.success) {
          this.publicModal.$emit("tips", {
            show: true,
            publicModalMessage: datas.msg,
            fontIcon: "errorWarning"
          });
          return false;
        }
        this.tableData = datas.data.list;
        this.totalCount = datas.data.total;
      });
    },
    // 查询
    searquFormstr(queryStr) {
      console.log(queryStr, "查询数据-")
      this.queryStr = queryStr
      this.getModelList()
    },
    // 查看
    checksVive() {
      this.dialogCheckControl = true
    },
    checkDialogsClosed() {
      this.dialogCheckControl = false
    }
  },
  filters: {
    defaultText(value) {
      if (!value) return "-";
      else {
        return value;
      }
    }
  }
};
</script>
<style scoped></style>
